<template>
  <el-form ref="form" :model="videoForm" label-width="80px">
  </el-form>
</template>

<script setup>
import { ref } from 'vue';
import { ElMessage } from 'element-plus';
const videoForm = ref({
  videoId: '',
  videoUrl: ''
});
const videoFlag = ref(false);
const Plus = ref(true);
const Path = ref({
  url: 'D:\\MyProject\\Pioneer\\Intelligent-Pension-Management\\pension-back-end\\video'
});
const videoUploadPercent = ref(0);
const uploadUrl = ref('http://localhost:8080' + '/diets/videoUpload');
const beforeUploadVideo = (file) => {
  const isLt5000M = file.size / 1024 / 1024 < 5000;
  const allowedTypes = [
    'video/mp4',
    'video/ogg',
    'video/flv',
    'video/avi',
    'video/wmv',
    'video/rmvb'
  ];

  if (!allowedTypes.includes(file.type)) {
    ElMessage.error('请上传正确的视频格式');
    return false;
  }

  if (!isLt5000M) {
    ElMessage.error('上传视频大小不能超过5000MB哦!');
    return false;
  }

  return true;
};

const uploadVideoProcess = (file) => {
  Plus.value = false;
  videoFlag.value = true;
  videoUploadPercent.value = Math.round(file.percentage);
};

const handleVideoSuccess = (res) => {
  Plus.value = false;
  videoUploadPercent.value = 100;
  console.log(res);

  if (res.resCode === '200') {
    videoForm.value.videoId = res.newVidoeName;
    videoForm.value.videoUrl = res.VideoUrl;
    ElMessage.success('视频上传成功！');
  } else {
    ElMessage.error('视频上传失败，请重新上传！');
  }

  setTimeout(() => {
    resetUploadStatus();
  }, 3000);
};

const resetUploadStatus = () => {
  videoFlag.value = false;
  Plus.value = true;
  videoUploadPercent.value = 0;
};

</script>

<style scoped>
.avatar-uploader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader:hover {
  border-color: #409EFF;
}

.el-upload__text {
  font-size: 14px;
  color: #606266;
  margin-top: 10px;
}

.el-upload__tip {
  font-size: 12px;
  color: #606266;
  margin-top: 10px;
}

.el-form-item {
  margin-bottom: 22px;
}
</style>